home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / CoreFoundation / CFBase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  8.0 KB  |  301 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        CFBase.h
  3.  
  4.      Contains:    CoreFoundation base types
  5.  
  6.      Version:    Technology:    Mac OS X
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1999 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __COREFOUNDATION_CFBASE__
  18. #define __COREFOUNDATION_CFBASE__
  19.  
  20. #ifndef __MACTYPES__
  21.     #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26. #if !defined(TRUE)
  27.     #define TRUE    1
  28. #endif
  29.     
  30. #if !defined(FALSE)
  31.     #define FALSE    0
  32. #endif
  33.  
  34.  
  35. #if defined(__WIN32__)
  36.     #undef CF_EXPORT
  37.     #if defined(CF_BUILDING_CF)
  38.         #define CF_EXPORT __declspec(dllexport) extern
  39.     #else
  40.         #define CF_EXPORT __declspec(dllimport) extern
  41.     #endif
  42. #elif defined(macintosh)
  43.     #if defined(__MWERKS__)
  44.         #define CF_EXPORT __declspec(export) extern
  45.     #endif
  46. #endif
  47.  
  48. #if !defined(CF_EXPORT)
  49.     #define CF_EXPORT extern
  50. #endif
  51.  
  52.  
  53. #if !defined(CF_INLINE)
  54.     #if defined(__GNUC__)
  55.         #define CF_INLINE static __inline__
  56.     #elif defined(__MWERKS__)
  57.         #define CF_INLINE static inline
  58.     #endif
  59. #endif
  60.  
  61.  
  62.  
  63. #if PRAGMA_ONCE
  64. #pragma once
  65. #endif
  66.  
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70.  
  71. #if PRAGMA_IMPORT
  72. #pragma import on
  73. #endif
  74.  
  75. #if PRAGMA_STRUCT_ALIGN
  76.     #pragma options align=mac68k
  77. #elif PRAGMA_STRUCT_PACKPUSH
  78.     #pragma pack(push, 2)
  79. #elif PRAGMA_STRUCT_PACK
  80.     #pragma pack(2)
  81. #endif
  82.  
  83. #if PRAGMA_ENUM_ALWAYSINT
  84.     #pragma enumsalwaysint on
  85. #elif PRAGMA_ENUM_OPTIONS
  86.     #pragma option enum=int
  87. #elif PRAGMA_ENUM_PACK
  88.     #if __option(pack_enums)
  89.         #define PRAGMA_ENUM_PACK__COREFOUNDATION_CFBASE__
  90.     #endif
  91.     #pragma options(!pack_enums)
  92. #endif
  93.  
  94. typedef UInt32                             CFTypeID;
  95. typedef UInt32                             CFOptionFlags;
  96. typedef UInt32                             CFHashCode;
  97. typedef SInt32                             CFIndex;
  98. #if !defined(__CFSTRING_STRUCT__)
  99.     #define __CFSTRING_STRUCT__ 1
  100.     typedef const struct __CFString * CFStringRef;
  101.     typedef struct __CFString * CFMutableStringRef;
  102. #endif
  103. /* Values returned from comparison functions */
  104.  
  105. enum CFComparisonResult {
  106.     kCFCompareLessThan            = -1,
  107.     kCFCompareEqualTo            = 0,
  108.     kCFCompareGreaterThan        = 1
  109. };
  110. typedef enum CFComparisonResult CFComparisonResult;
  111.  
  112. /* A standard comparison function */
  113. typedef CALLBACK_API_C( CFComparisonResult , CFComparatorFunction )(const void *val1, const void *val2, void *context);
  114. /* Constant used by some functions to indicate failed searches. */
  115. /* This is of type CFIndex. */
  116. enum {
  117.     kCFNotFound                    = -1
  118. };
  119.  
  120. /* Range type */
  121.  
  122. struct CFRange {
  123.     CFIndex                         location;
  124.     CFIndex                         length;
  125. };
  126. typedef struct CFRange                    CFRange;
  127.  
  128. #if defined(CF_INLINE)
  129. CF_INLINE CFRange CFRangeMake(CFIndex loc, CFIndex len) {
  130.     CFRange range;
  131.     range.location = loc;
  132.     range.length = len;
  133.     return range;
  134. }
  135. #else
  136. #define CFRangeMake(LOC, LEN) __CFRangeMake(LOC, LEN)
  137. #endif
  138.  
  139. EXTERN_API_C( CFRange )
  140. __CFRangeMake                    (CFIndex                 loc,
  141.                                  CFIndex                 len);
  142.  
  143. /* Private; do not use */
  144. /* Allocator API
  145.  
  146.    Most of the time when specifying an allocator to Create functions, the NULL 
  147.    argument indicates "use the default"; this is the same as using kCFAllocatorDefault 
  148.    or the return value from CFAllocatorGetDefault().  This assures that you will use 
  149.    the allocator in effect at that time.
  150.    
  151.    You should rarely use kCFAllocatorSystemDefault, the default default allocator.
  152. */
  153. typedef const struct __CFAllocator * CFAllocatorRef;
  154. /* This is a synonym for NULL, if you'd rather use a named constant. */
  155. extern const CFAllocatorRef kCFAllocatorDefault;
  156. /* Default system allocator. */
  157. extern const CFAllocatorRef kCFAllocatorSystemDefault;
  158. /* Null allocator which does nothing and allocates no memory. */
  159. extern const CFAllocatorRef kCFAllocatorNull;
  160. /* Special allocator argument to CFAllocatorCreate() which means
  161.    "use the functions given in the context to allocate the allocator itself as well". 
  162. */
  163. extern const CFAllocatorRef kCFAllocatorUseContext;
  164. typedef CALLBACK_API_C( const void *, CFAllocatorRetainCallBack )(const void *info);
  165. typedef CALLBACK_API_C( void , CFAllocatorReleaseCallBack )(const void *info);
  166. typedef CALLBACK_API_C( CFStringRef , CFAllocatorCopyDescriptionCallBack )(const void *info);
  167. typedef CALLBACK_API_C( void *, CFAllocatorAllocateCallBack )(CFIndex allocSize, CFOptionFlags hint, void *info);
  168. typedef CALLBACK_API_C( void *, CFAllocatorReallocateCallBack )(void *ptr, CFIndex newsize, CFOptionFlags hint, void *info);
  169. typedef CALLBACK_API_C( void , CFAllocatorDeallocateCallBack )(void *ptr, void *info);
  170. typedef CALLBACK_API_C( CFIndex , CFAllocatorPreferredSizeCallBack )(CFIndex size, CFOptionFlags hint, void *info);
  171.  
  172. struct CFAllocatorContext {
  173.     CFIndex                         version;
  174.     void *                            info;
  175.     CFAllocatorRetainCallBack         retain;
  176.     CFAllocatorReleaseCallBack         release;
  177.     CFAllocatorCopyDescriptionCallBack  copyDescription;
  178.     CFAllocatorAllocateCallBack     allocate;
  179.     CFAllocatorReallocateCallBack     reallocate;
  180.     CFAllocatorDeallocateCallBack     deallocate;
  181.     CFAllocatorPreferredSizeCallBack  preferredSize;
  182. };
  183. typedef struct CFAllocatorContext        CFAllocatorContext;
  184. EXTERN_API_C( CFTypeID )
  185. CFAllocatorGetTypeID            (void);
  186.  
  187.  
  188. /* CFAllocatorSetDefault() sets the allocator that is used in the current thread
  189.    whenever NULL is specified as an allocator argument. This means that most, if
  190.    not all allocations will go through this allocator. It also means that any
  191.    allocator set as the default needs to be ready to deal with arbitrary memory
  192.    allocation requests; in addition, the size and number of requests will change
  193.    between releases.
  194.  
  195.    If you wish to use a custom allocator in a context, it's best to provide it as
  196.    the argument to the various creation functions rather than setting it as the
  197.    default. Setting the default allocator is not encouraged.
  198.  
  199.    If you do set an allocator as the default, either do it for all time in your
  200.    app, or do it in a nested fashion (by restoring the previous allocator when
  201.    you exit your context). The latter might be appropriate for plug-ins or
  202.    libraries that wish to set the default allocator.
  203. */
  204. EXTERN_API_C( void )
  205. CFAllocatorSetDefault            (CFAllocatorRef         allocator);
  206.  
  207. EXTERN_API_C( CFAllocatorRef )
  208. CFAllocatorGetDefault            (void);
  209.  
  210.  
  211. EXTERN_API_C( CFAllocatorRef )
  212. CFAllocatorCreate                (CFAllocatorRef         allocator,
  213.                                  CFAllocatorContext *    context);
  214.  
  215.  
  216. EXTERN_API_C( void *)
  217. CFAllocatorAllocate                (CFAllocatorRef         allocator,
  218.                                  CFIndex                 size,
  219.                                  CFOptionFlags             hint);
  220.  
  221. EXTERN_API_C( void *)
  222. CFAllocatorReallocate            (CFAllocatorRef         allocator,
  223.                                  void *                    ptr,
  224.                                  CFIndex                 newsize,
  225.                                  CFOptionFlags             hint);
  226.  
  227. EXTERN_API_C( void )
  228. CFAllocatorDeallocate            (CFAllocatorRef         allocator,
  229.                                  void *                    ptr);
  230.  
  231. EXTERN_API_C( CFIndex )
  232. CFAllocatorGetPreferredSizeForSize (CFAllocatorRef         allocator,
  233.                                  CFIndex                 size,
  234.                                  CFOptionFlags             hint);
  235.  
  236. EXTERN_API_C( void )
  237. CFAllocatorGetContext            (CFAllocatorRef         allocator,
  238.                                  CFAllocatorContext *    context);
  239.  
  240. /* Base "type" of all "CF objects", and polymorphic functions on them */
  241.  
  242. typedef const void *                    CFTypeRef;
  243. EXTERN_API_C( CFTypeID )
  244. CFGetTypeID                        (CFTypeRef                 cf);
  245.  
  246. EXTERN_API_C( CFStringRef )
  247. CFCopyTypeIDDescription            (CFTypeID                 theType);
  248.  
  249.  
  250. EXTERN_API_C( CFTypeRef )
  251. CFRetain                        (CFTypeRef                 cf);
  252.  
  253. EXTERN_API_C( void )
  254. CFRelease                        (CFTypeRef                 cf);
  255.  
  256. EXTERN_API_C( CFIndex )
  257. CFGetRetainCount                (CFTypeRef                 cf);
  258.  
  259. EXTERN_API_C( Boolean )
  260. CFEqual                            (CFTypeRef                 cf1,
  261.                                  CFTypeRef                 cf2);
  262.  
  263. EXTERN_API_C( CFHashCode )
  264. CFHash                            (CFTypeRef                 cf);
  265.  
  266. EXTERN_API_C( CFStringRef )
  267. CFCopyDescription                (CFTypeRef                 cf);
  268.  
  269. EXTERN_API_C( CFAllocatorRef )
  270. CFGetAllocator                    (CFTypeRef                 cf);
  271.  
  272.  
  273. #if PRAGMA_ENUM_ALWAYSINT
  274.     #pragma enumsalwaysint reset
  275. #elif PRAGMA_ENUM_OPTIONS
  276.     #pragma option enum=reset
  277. #elif defined(PRAGMA_ENUM_PACK__COREFOUNDATION_CFBASE__)
  278.     #pragma options(pack_enums)
  279. #endif
  280.  
  281. #if PRAGMA_STRUCT_ALIGN
  282.     #pragma options align=reset
  283. #elif PRAGMA_STRUCT_PACKPUSH
  284.     #pragma pack(pop)
  285. #elif PRAGMA_STRUCT_PACK
  286.     #pragma pack()
  287. #endif
  288.  
  289. #ifdef PRAGMA_IMPORT_OFF
  290. #pragma import off
  291. #elif PRAGMA_IMPORT
  292. #pragma import reset
  293. #endif
  294.  
  295. #ifdef __cplusplus
  296. }
  297. #endif
  298.  
  299. #endif /* __COREFOUNDATION_CFBASE__ */
  300.  
  301.